from sqlalchemy import (
    Column,
    Index,
    Integer,
    Text,
    Unicode,
    Table,
    ForeignKey
)
from sqlalchemy.orm import relationship
from .meta import Base

group_permission=Table('group_permission',Base.metadata,
        Column('group_id',Integer,ForeignKey('groups.id'),primary_key=True),
        Column('permission_id',Integer,ForeignKey('permissions.id'),primary_key=True)
    )

class Group(Base):
    __tablename__='groups'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(50), nullable=True, unique=True)

    permissions=relationship("Permission",backref='groups',secondary=group_permission)